package com.joolun.web.api.foruminfo.service.impl;

import java.util.List;

import com.joolun.common.utils.DateUtils;
import com.joolun.weixin.entity.WxUser;
import com.joolun.weixin.mapper.WxUserMapper;
import com.joolun.weixin.utils.ThirdSessionHolder;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.joolun.web.api.foruminfo.mapper.ForumInfoMapper;
import com.joolun.web.api.foruminfo.domain.ForumInfo;
import com.joolun.web.api.foruminfo.service.IForumInfoService;

/**
 * 帖子信息Service业务层处理
 *
 * @author joolun
 * @date 2025-04-12
 */
@Service
public class ForumInfoServiceImpl implements IForumInfoService {
	@Autowired
	private ForumInfoMapper forumInfoMapper;
	@Autowired
	private WxUserMapper wxUserMapper;

	/**
	 * 查询帖子信息
	 *
	 * @param id 帖子信息主键
	 * @return 帖子信息
	 */
	@Override
	public ForumInfo selectForumInfoById(Long id) {
		return forumInfoMapper.selectForumInfoById(id);
	}

	/**
	 * 查询帖子信息列表
	 *
	 * @param forumInfo 帖子信息
	 * @return 帖子信息
	 */
	@Override
	public List<ForumInfo> selectForumInfoList(ForumInfo forumInfo) {
		return forumInfoMapper.selectForumInfoList(forumInfo);
	}

	/**
	 * 新增帖子信息
	 *
	 * @param forumInfo 帖子信息
	 * @return 结果
	 */
	@Override
	public int insertForumInfo(ForumInfo forumInfo) {
		WxUser wxUser = wxUserMapper.selectById(forumInfo.getUserId());
		forumInfo.setUserName(wxUser.getNickName());

		return forumInfoMapper.insertForumInfo(forumInfo);
	}

	/**
	 * 修改帖子信息
	 *
	 * @param forumInfo 帖子信息
	 * @return 结果
	 */
	@Override
	public int updateForumInfo(ForumInfo forumInfo) {
		forumInfo.setUpdateTime(DateUtils.getNowDate());
		return forumInfoMapper.updateForumInfo(forumInfo);
	}

	/**
	 * 批量删除帖子信息
	 *
	 * @param ids 需要删除的帖子信息主键
	 * @return 结果
	 */
	@Override
	public int deleteForumInfoByIds(Long[] ids) {
		return forumInfoMapper.deleteForumInfoByIds(ids);
	}

	/**
	 * 删除帖子信息信息
	 *
	 * @param id 帖子信息主键
	 * @return 结果
	 */
	@Override
	public int deleteForumInfoById(Long id) {
		return forumInfoMapper.deleteForumInfoById(id);
	}
}
